package com.hzhc.controller.pad;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.entity.DeclareCar;
import com.hzhc.service.DeclareCarService;
import com.hzhc.vo.CntrTallyVo;
import com.hzhc.vo.DeclareCarVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName: LoginController
 * @Description:
 * @version 1.0
 * @author: 功不唐捐
 * @Date: 2024-06-03
 */
@RestController
@RequestMapping("/ipad")
@RequiredArgsConstructor
public class WaitingWorkCarController {

	private final DeclareCarService declareCarService;

	/**
	 * 获取等待作业车辆列表
	 * 
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unused")
	@PostMapping("/getWaitingWorkCar")
	public Object getWaitingWorkCar(HttpServletRequest request, @RequestBody String json) {
		String deviceNo = request.getHeader("deviceNo");// 设备号
		// TODO 根据设备号获取该设备所在的区域。
		JSONObject object = JSONObject.parseObject(json);
		DeclareCarVo declareCarVo = new DeclareCarVo();
		if (StrUtil.isNotBlank(object.getString("ywcode"))) {
			 declareCarVo.setYwcode(object.getString("ywcode"));
		}
		if (StrUtil.isNotBlank(object.getString("carNo"))) {
			declareCarVo.setCarNo(object.getString("carNo"));
		}
		JSONObject jsonObject = new JSONObject();
		List<DeclareCarVo> declareCarVos = declareCarService.getIpadTodayCarList(declareCarVo);
		jsonObject.put("code", "200");
		jsonObject.put("data", declareCarVos);
		jsonObject.put("totalRow", declareCarVos.size());
		jsonObject.put("success", true);
		return jsonObject;
	}

	@PostMapping("/workCarEnd")
	@SysTemLog(operModul = "车辆结束", operType = "结束", operDesc = "车辆结束功能", modular = "IPAD")
	public Object workCarEnd(@RequestBody CntrTallyVo vo) {
		DeclareCar declareCar = declareCarService.getById(vo.getDeclareId());
		declareCar.setTallyFlag(10);
		declareCar.setTallyFlagB(10);
		declareCarService.updateById(declareCar);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("code", "200");
		jsonObject.put("msg", "操作成功");
		jsonObject.put("data", null);
		jsonObject.put("success", true);
		return jsonObject;
	}
}
